// pages/enterInfo/enterInfo.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userInfo: '',
    formlist: [
      { label: '个人资料',type: 'label' },
      { isrequire: true,label:'姓名',value: '',tips:'请填写',type:'input'},
      { isrequire: true, label: '性别', value: '', tips: '请选择', type: 'select' ,data:[]},
      { isrequire: true, label: '籍贯', value: '', tips: '请选择', type: 'select',mode:'region'},
      { isrequire: true, label: '街道', value: '', tips: '请选择', type: 'select' },
      { isrequire: true, label: '身份证号', value: '', tips: '请填写', type: 'input' },
      { isrequire: true, label: '出生年月', value: '', tips: '请选择', type: 'select', mode: 'date' },
      { isrequire: true, label: '居住地址', value: '', tips: '请填写', type: 'input' },
      { isrequire: true, label: '街道', value: '', tips: '请选择', type: 'select' },
      { isrequire: true, label: '详细地址', value: '', tips: '请选择', type: 'select' },
      { isrequire: true, label: '手机号', value: '', tips: '请填写', type: 'input' },   
      { label: '其他信息', type: 'label' },
      { isrequire: false, label: '行业', value: '', tips: '请选择', type: 'select' },
      { isrequire: false, label: '工作单位', value: '', tips: '请填写', type: 'input' },
      { isrequire: false, label: '工作地址', value: '', tips: '请填写', type: 'input' },
      { isrequire: false, label: '职位', value: '',tips: '请填写', type: 'input' },
      { isrequire: false, label: '兴趣', value: '', tips: '请填写', type: 'input' },
      { isrequire: false, label: '车辆详情', value: '', tips: '请选择', type: 'selectall', url:'/pages/carinfo/carinfo' },
      { isrequire: false, label: '教育经历', value: '', tips: '请选择', type: 'select' },
      { label: '更多信息', type: 'label' }
    ],
    keys: ''
  },
  bindPickerChange: function (e) {
    var arr = [];
    arr = this.data.formlist;
    if (e.target.dataset.type != undefined){
      arr[e.target.dataset.index].value = e.detail.value;
    }
    else{
      arr[e.target.dataset.index].value = this.data.formlist[e.target.dataset.index].data[e.detail.value];
    }
    this.setData({
      formlist: arr
    });
    wx.setStorage({
      key: e.target.dataset.index+'',
      data: arr[e.target.dataset.index].value
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    this.setData({
      userInfo: JSON.parse(wx.getStorageSync('userInfo'))
    })
    if (options.con != undefined){
      this.bindobj('formlist', options.con, 'value', options.index);
      wx.setStorage({
        key: options.index+'',
        data: options.con
      })
    }     
    wx.getStorageInfo({
      success: function (res) {
        that.setData({
          keys: res.keys
        });
        for (var i = 0; i < that.data.keys.length-1; i++) {     
          var value = wx.getStorageSync(that.data.keys[i]);
          var oindex = parseInt(that.data.keys[i]);
          that.bindobj('formlist', value, 'value', oindex);
        }
      }
    });
    
    //wx.clearStorage();
  },
  bindobj: function (oldval,newval,key,index) {
    var arr = [];
    arr = this.data[oldval];
    arr[index][key] = newval;
    this.setData({
      formlist: arr
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    //wx.clearStorage();
    var arr = ['男', '女'];
    this.bindobj('formlist', arr,'data',2);
  },
  
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})